<template>
    <view class="xh-view">
        <u-input :border="false" type="textarea" placeholder="请填写内容" v-model="dataValue" @input="valueChange" :disabled="disabled" 
            clearable></u-input>
    </view>
</template>

<script>
    export default {
        props: {
            /** 值 */
            value: {
                type: [String, Number],
                default: ''
            },
            /** 索引值 用于更新数据 */
            index: Number,
            /** 包含数据源 */
            item: Object,
            disabled: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                dataValue: '',
            }
        },
        computed: {
            type() {
                if (this.item && this.item.form_type == 'password') {
                    return this.item.form_type
                } else {
                    return 'text'
                }
            }
        },

        watch: {
            value: function(val) {
                this.dataValue = val
            }
        },
        methods: {
            clear() {
                this.dataValue = '';
                this.valueChange();
            },

            valueChange() {
                let data = {
                    index: this.index,
                    fieldName: this.item.data.fieldName,
                    value: this.dataValue.trim()
                }
                this.$emit('value-change', data)
            },
        }
    }
</script>

<style>
    .xh-view{
        width: 100%;
    }
</style>
